'use strict';
// 定点产品列表管理
app.controller('fixedpointproduct', ['$scope', '$http', 'commonFactory', 'toaster', '$timeout', '$modal', '$interval', function ($scope, $http, commonFactory, toaster, $timeout, $modal, $interval) {
    var initdata = function () {
        $scope.godata = function () {
            requestProductList()
        }

        //下一页
        $scope.next = function () {
            if ($scope.page) {
                if ($scope.requestArr.index >= $scope.page) {//判断最大页码
                    $scope.requestArr.index = $scope.page;
                    return false;
                }
                $scope.requestArr.index++
                requestProductList();
            }
        }
        //end
        $scope.end = function () {
            if ($scope.page) {
                $scope.requestArr.index = $scope.page;
                requestProductList();
            }
        }
        //上一页
        $scope.prev = function () {
            if ($scope.requestArr.index <= 1) {//判断最小页码
                $scope.requestArr.index = 1;
                return false;
            }
            $scope.requestArr.index--;
            requestProductList()
        }
        $scope.requestArr = {//查询条件
            ProductName: '',
            ProductCode: '',
            UserId: '',//借款人id
            ProductStatus: '0',
            AssignInvestUserId: '',//投资人id
            FullstartTime: '',
            FullendTime: '',
            size:10,
            index:1
        }
        //导出
        $scope.export = function () {
            if ($scope.requestArr.FullendTime == undefined || $scope.requestArr.FullendTime == '') {
                $scope.requestArr.FullendTime = '1900-01-01'
            } else {
                $scope.requestArr.FullendTime = commonFactory.DateFormat($scope.requestArr.FullendTime, 1);
            }
            if ($scope.requestArr.FullstartTime == undefined || $scope.requestArr.FullstartTime == "") {
                $scope.requestArr.FullstartTime = '1900-01-01'
            } else {
                $scope.requestArr.FullstartTime = commonFactory.DateFormat($scope.requestArr.FullstartTime, 1)
            }
            if ($scope.requestArr.ProductName == undefined || $scope.requestArr.ProductName == '') {
                $scope.requestArr.ProductName = ''
            }
            if ($scope.requestArr.ProductCode == undefined || $scope.requestArr.ProductCode == '') {
                $scope.requestArr.ProductCode = ''
            }
            if ($scope.requestArr.UserId == undefined || $scope.requestArr.UserId == '') {
                $scope.requestArr.UserId = 0
            }
            if ($scope.requestArr.AssignInvestUserId == undefined || $scope.requestArr.AssignInvestUserId == '') {
                $scope.requestArr.AssignInvestUserId = 0
            }
            $scope.gourl = commonFactory.pointurl + '/api/Product/Expoit?FullEnd=' +
                $scope.requestArr.FullendTime + '&FullStart=' +
                $scope.requestArr.FullstartTime + '&ProductCode=' +
                $scope.requestArr.ProductCode + '&ProductName=' +
                $scope.requestArr.ProductName + '&ProductStatus=' +
                $scope.requestArr.ProductStatus + '&AssignUserId=' +
                $scope.requestArr.UserId + '&AssignInvestUserId=' + $scope.requestArr.AssignInvestUserId;
            $scope.requestArr.FullendTime = '';//处理跳转后搜索框中赋值问题
            $scope.requestArr.FullstartTime = '';
            $scope.requestArr.UserId ='';
            $scope.requestArr.AssignInvestUserId = '';
        }

        //查询
        $scope.search = function () {
            $scope.graybtn = true;
            $scope.requestArr.index = 1 //查询后在第一页显示
            if (!$scope.requestArr.FullstartTime) {//处理时间NaN
                $scope.FullstartTime = ''
            } else {
                $scope.FullstartTime = commonFactory.DateFormat($scope.requestArr.FullstartTime, 1)
            }
            if (!$scope.requestArr.FullendTime) {
                $scope.FullendTime = ''
            } else {
                $scope.FullendTime = commonFactory.DateFormat($scope.requestArr.FullendTime, 1)
            }

            requestProductList();
        }
        // 删除缓存
        $scope.delCache = function () {
            commonFactory.ajax(commonFactory.pointurl + "/api/Product/DeleteCache ", {}, function (result) {
                toaster.pop('success', '成功', '删除成功');
            }, function () {
                toaster.pop('error', '失败', '后台未返回报错');
            }, "post");
        }
        var requestProductList = function () {
            commonFactory.loading(true)  
            commonFactory.ajax(commonFactory.pointurl + "/api/product/QueryProduct", $scope.requestArr, function (result) {
                commonFactory.loading(false)  
                $scope.graybtn = false;
                $scope.QueryLoanProductList = result.data;
                $scope.QueryLoanProductListTotal = result.count;
                $scope.page = Math.ceil(result.count / $scope.requestArr.size);
                $scope.status = function (sta) {
                    switch (sta) {
                        case 1: return '未发布';
                        case 2: return '已发布';
                        case 3: return '募资中';
                        case 4: return '已满标';
                        case 5: return '还款中';
                        case 6: return '提前还清';
                        case 7: return '已还清';
                        case 8: return '等待推送至银行';
                        case 13: return '流标';
                        case 15: return '草稿';
                        case 16: return '已删除';
                    }
                }
            }, function () {
                commonFactory.loading(false)
                $scope.graybtn = false;
                toaster.pop('error', '失败', '后台未返回报错');
            }, "post");
        }
        requestProductList();
        //复制
        $scope.copyurl = ''
        $scope.jsCopy = function (id) {
            $scope.copyurl = commonFactory.copyurl + id
            $timeout(function () {
                document.getElementById("textid").select();
                document.execCommand("Copy");
                toaster.pop('success', '', '复制成功');
            }, 100)

        }
        //募资中
        $scope.Raise = function (pId) {
            var modalInstance = $modal.open({
                templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                controller: ['$scope', '$modalInstance', 'raise', function ($scope, $modalInstance, raise) {
                    $scope.raise = raise;
                    var off = true;
                    $scope.ok = function () {
                        if (!off) { return false }
                        off = false;
                        commonFactory.ajax(commonFactory.pointurl + "/api/product/Release?productId=" + raise, {}, function (result) {
                            if (result.code == 1) {
                                toaster.pop('success', '成功', '募资成功');
                                $modalInstance.close();
                            } else {
                                toaster.pop('error', '失败', result.data);
                                $modalInstance.close();
                            }
                        }, function () {
                            toaster.pop('error', '失败', '后台返回报错');
                        }, "post");
                    }
                    $scope.cancel = function () {
                        $modalInstance.close();
                    };
                }
                ],
                size: 'sm',
                backdrop: false,
                resolve: {
                    raise: function () {
                        return pId;
                    }
                }
            });
            modalInstance.result.then(function () {
                requestProductList();
            }, function () {
            });
        }
        //发布
        $scope.Release = function (pid) {
            var modalInstance = $modal.open({
                templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                controller: ['$scope', '$modalInstance', 'Release', function ($scope, $modalInstance, Release) {
                    $scope.Release = Release;
                    var off = true;
                    $scope.ok = function () {
                        if (!off) { return false }
                        off = false;
                        commonFactory.ajax(commonFactory.pointurl + "/api/product/Publish?productId=" + Release, {}, function (result) {
                            if (result.code == 1) {
                                toaster.pop('success', '成功', '发布成功');
                                $modalInstance.close();
                            } else {
                                toaster.pop('error', '失败', result.resposeData);
                                $modalInstance.close();
                            }
                        }, function () {
                            toaster.pop('error', '失败', '后台未返回报错');
                        }, "post");
                    }
                    $scope.cancel = function () {
                        $modalInstance.close();
                    };
                }
                ],
                size: 'sm',
                backdrop: false,
                resolve: {
                    Release: function () {
                        return pid;
                    }
                }
            });
            modalInstance.result.then(function () {
                requestProductList();
            }, function () {
            });

        }
        //编辑
        $scope.edit = function (pid) {
            var modalInstance = $modal.open({
                templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                controller: 'editfixedpoint',
                size: 'lg',
                backdrop: true,
                resolve: {
                    edit: function () {
                        return pid;
                    }
                }
            });
            modalInstance.result.then(function () {
                requestProductList();
            }, function () {
            });
        }
        // 添加
        $scope.addproductd = function () {
            var modalInstance = $modal.open({
                templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                controller: 'addfixedpoint',
                size: 'lg',
                backdrop: true
            });
            modalInstance.result.then(function () {
                requestProductList();
            }, function () {
            });
        }
        // 删除
        $scope.delete = function (obj) {
            var modalInstance = $modal.open({
                templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                controller: ['$scope', '$modalInstance', 'items', 'toaster', 'commonFactory', function ($scope, $modalInstance, items, toaster, commonFactory) {
                    $scope.items = items;
                    $scope.ok = function () {
                        //删除
                        commonFactory.loading(true)
                        commonFactory.ajax(commonFactory.pointurl + "/api/Product/Delete?productid=" + $scope.items.Id, {}, function (result) {
                            commonFactory.loading(false)
                            if (result.Code == 1) {
                                toaster.pop('success', '成功', '删除成功');
                                $modalInstance.close();
                            } else {
                                toaster.pop('error', '失败', result.data);
                                $modalInstance.close();
                            }
                        }, function () {
                            commonFactory.loading(false)
                            toaster.pop('error', '失败', '后台未返回报错');
                        }, "post");
                    }

                    $scope.cancel = function () {
                        $modalInstance.close('cancel');
                    };
                }],
                size: 'sm',
                backdrop: false,
                resolve: {
                    items: function () {
                        return obj;
                    }
                }
            });
            modalInstance.result.then(function () {
                requestProductList();
            }, function () {

            });
        };
        //一键还款
        $scope.hcash = function (pid) {
            commonFactory.ajax(commonFactory.pointurl + "/api/Product/GetBusinessAuthByProductId/" + pid, {}, function (result) {
                if (result.code == 1) {
                    $scope.formdata = result.data.result;
                    var formObject = document.querySelector('#idmyForm')
                    formObject.action = result.data.url
                    $timeout(function () {
                        formObject.submit();
                    }, 50)
                }
            }, function () { }, 'get')
        }
        // 是否授权
        $scope.editstatus = function (id, status) {
            var modalInstance = $modal.open({
                templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
                controller: ['$scope', '$modalInstance', 'editstatus', function ($scope, $modalInstance, editstatus) {
                    $scope.editstatusid = id;//弹出框判断
                    $scope.editstatus = editstatus;//绑定状态
                    var off = true;
                    $timeout(function(){
                        $('#hideInput').focus()
                    },100)
                    $scope.ok = function () {
                        if (!off) { return false }
                        off = false;
                        commonFactory.loading(true)
                        commonFactory.ajax(commonFactory.pointurl + "/api/product/EditProductAuthStatus", { '': id }, function (result) {
                            commonFactory.loading(false)
                            if (result.code == 1) {
                                toaster.pop('success', '成功', '修改成功');

                                $modalInstance.close();
                            } else {
                                toaster.pop('error', '', '失败');
                                $modalInstance.close();
                            }
                        }, function () {
                            commonFactory.loading(false)
                            toaster.pop('error', '失败', '后台未返回报错');
                        }, "post");
                    }
                    $scope.cancel = function () {
                        $modalInstance.close();
                    };
                    $scope.loginevent = function (e) {
                        if (e.keyCode == 13) {
                            $scope.ok();
                        }
                    }
                }
                ],
                size: 'sm',
                backdrop: false,
                resolve: {
                    editstatus: function () {
                        return status;
                    }
                }
            });
            modalInstance.result.then(function () {
                requestProductList();
            }, function () {
            });
        }
    }

    initdata();
}]);
// 添加产品
app.controller('addfixedpoint', ['$scope', '$http', 'commonFactory', 'toaster', '$timeout', '$modalInstance', function ($scope, $http, commonFactory, toaster, $timeout, $modalInstance) {
    $scope.addfixedpoint = true
    $scope.allData = {
        Id: '',//Id
        AssignUserId: '',// 借款人Id
        AssignInvestUserId: '',// 投资人Id
        ShowRate: '',// 显示加息
        ProductName: "",// 产品名称
        LoanPrice: "",// 贷款金额
        ContractNo: "",// 债权编号
        AnnualRateOfYear: "",// 贷款年利率
        LoanPeriod: "",// 贷款周期
        BusinessTypeId: "1",// 业务类型
        Description: ''
    }
    $scope.nocilck = true
    $scope.addProduct = function () {
        var all = $(".forminfo")
        var number = $(".forminfo[type='number']")
        for (var i = all.length - 1; i >= 0; i--) {
            if ($(all[i]).val() == "? string: ?" || $(all[i]).val() == "") {
                toaster.pop('warning', '', '数据不能为空');
                return;
            }
        }
        for (var i = number.length - 1; i >= 0; i--) {
            if ($(number[i]).val() % 1 != 0) {
                toaster.pop('warning', '', '数值必须为整数');
                return;
            }
        }
        $scope.nocilck = false
        commonFactory.loading(true)
        commonFactory.ajax(commonFactory.pointurl + "/api/product/CreateProduct", $scope.allData, function (result) {
            $scope.nocilck = true
            commonFactory.loading(false)
            if (result.code == 1) {
                toaster.pop('success', '', '添加成功');
                $modalInstance.close()
            } else {
                toaster.pop('error', '', result.data);
            }
        }, function () {
            commonFactory.loading(false)
            toaster.pop('error', '', '后台报错');
        }, "post");
    }
    $scope.mobile = { mobile: '', toumobile: '' };
    var mobile = '';
    $scope.getUserId = function (num) {
        if (num == 1) {
            if (!$scope.mobile.mobile) {
                toaster.pop('error', '', '请输入正确的借款人手机号');
                return false
            }
            mobile = $scope.mobile.mobile
        } else if (num == 2) {
            if (!$scope.mobile.toumobile) {
                toaster.pop('error', '', '请输入正确的投资人手机号');
                return false
            }
            mobile = $scope.mobile.toumobile
        }
        if (mobile == "") {
            toaster.pop('warning', '', '查询内容不能为空');
        } else {
            commonFactory.loading(true)
            commonFactory.ajax(commonFactory.pointurl + "/api/user/GetUserByMobile?phone=" + mobile, {}, function (result) {
                commonFactory.loading(false)
                if (result == null) {
                    toaster.pop('warning', '', '查无此人');
                } else if (result.code == 1) {
                    if (num == 1) {
                        $scope.allData.AssignUserId = result.data;
                    } else if (num == 2) {
                        $scope.allData.AssignInvestUserId = result.data;
                    }
                } else {
                    commonFactory.loading(false)
                    toaster.pop('warning', '', result.data);
                }
            }, function () {
                toaster.pop('warning', '', '后台报错');
            }, "post");
        }
    }

    $scope.loginevent = function (e) {
        if (e.keyCode == 13) {
            $scope.getUserId();
        }
    }
}]);
// 编辑产品editfixedpoint
app.controller('editfixedpoint', ['$scope', '$http', 'commonFactory', 'toaster', '$timeout', 'edit', '$modalInstance', '$interval', function ($scope, $http, commonFactory, toaster, $timeout, edit, $modalInstance, $interval) {
    $scope.editfixedpoint = edit;
    // 通过id 获取 要编辑产品数据
    commonFactory.ajax(commonFactory.pointurl + "/api/Product/GetProductDto", { '': $scope.editfixedpoint }, function (result) {
        // $scope.allData = result;
        $scope.allData = {//
            Id: result.id,//Id
            AssignUserId: result.assignUserId,// 借款人Id
            AssignInvestUserId: result.assignInvestUserId,// 投资人Id
            ShowRate: result.showRate,// 显示加息
            ProductName: result.productName,// 产品名称
            LoanPrice: result.loanPrice,// 贷款金额
            ContractNo: result.contractNo,// 债权编号
            AnnualRateOfYear: result.annualRateOfYear,// 贷款年利率
            LoanPeriod: result.loanPeriod,// 贷款周期
            BusinessTypeId: result.businessTypeId,// 业务类型
            Description: ''//无用但是后台要求得传
        }
        if (result == null) {
            toaster.pop('warning', '', '未查询到此Id');
        }
    }, function () {
        toaster.pop('warning', '', '后台报错');
    }, "post");
    $scope.editProduct = function () {
        var all = $(".forminfo")
        var number = $(".forminfo[type='number']")
        for (var i = all.length - 1; i >= 0; i--) {
            if ($(all[i]).val() == "? string: ?" || $(all[i]).val() == "") {
                toaster.pop('warning', '', '数据不能为空');
                return;
            }
        }
        for (var i = number.length - 1; i >= 0; i--) {
            if ($(number[i]).val() % 1 != 0) {
                toaster.pop('warning', '', '数值必须为整数');
                return;
            }
        }
        commonFactory.loading(true)
        commonFactory.ajax(commonFactory.pointurl + "/api/product/EditProduct", $scope.allData, function (result) {
            commonFactory.loading(false)
            if (result.code == 1) {
                localStorage.getItem("editProductId", "");
                toaster.pop('success', '', '编辑成功');
                $modalInstance.close();
            } else {
                toaster.pop('error', '失败', result.data);
                $modalInstance.close();
            }
        }, function () {
            commonFactory.loading(false)
            toaster.pop('error', '', '后台报错');
        }, "post");
    }


    $scope.mobile = { mobile: '', toumobile: '' };
    var mobile = ''
    $scope.getUserId = function (num) {
        if (num == 1) {
            if (!$scope.mobile.mobile) {
                toaster.pop('error', '', '请输入正确的借款人手机号');
                return false
            }
            mobile = $scope.mobile.mobile
        } else if (num == 2) {
            if (!$scope.mobile.toumobile) {
                toaster.pop('error', '', '请输入正确的投资人手机号');
                return false
            }
            mobile = $scope.mobile.toumobile
        }
        if (mobile == "") {
            toaster.pop('warning', '', '查询内容不能为空');
        } else {
            commonFactory.loading(true)
            commonFactory.ajax(commonFactory.pointurl + "/api/user/GetUserByMobile?phone=" + mobile, {}, function (result) {
                commonFactory.loading(false)
                if (result == null) {
                    toaster.pop('warning', '', '查无此人');
                } else {
                    if (!$scope.allData) {
                        // $scope.borrow = result.Id;
                    } else if (result.code == 1) {
                        if (num == 1) {
                            $scope.allData.AssignUserId = result.data;
                        } else if (num == 2) {
                            $scope.allData.AssignInvestUserId = result.data;
                        }
                    } else {
                        toaster.pop('warning', '', result.data);
                    }
                }
            }, function () {
                commonFactory.loading(false)
            }, "post");

        }
    }
    $scope.loginevent = function (e) {
        if (e.keyCode == 13) {
            $scope.getUserId();
        }
    }
}]);


// 定点借款投资人管理
app.controller('fixedpointinvestor', ['$scope', '$http', 'commonFactory', 'toaster', '$timeout', '$modal', function ($scope, $http, commonFactory, toaster, $timeout, $modal) {
    $scope.BorrData = {
        Index: 1,
        Size: 10,
        UserId: '',
        FullName: '',
        UserType: '0',
        UserName: ''
    }
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.BorrData.Index >= $scope.page) {//判断最大页码
                $scope.BorrData.Index = $scope.page;
                return false;
            }
            $scope.BorrData.Index++
            requestBorrList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.BorrData.Index <= 1) {//判断最小页码
            $scope.BorrData.Index = 1;
            return false;
        }
        $scope.BorrData.Index--;
        requestBorrList()
    }
    // 查询
    $scope.queryBorr = function () {
        $scope.graybtn = true;
        $scope.BorrData.Index = 1;
        requestBorrList();
    }
    var checkinp = function () {
        if (!$scope.addBorrMoblie) {
            toaster.pop('warning', '', '请输入借款人手机号');
            return
        }
        return true
    }
    $scope.isadd = true;
    $scope.addBorrMoblie = "";
    $scope.usertype = "0";
    $scope.addBorr = function () {
        if (checkinp() && $scope.isadd) {
            $scope.isadd = false
            commonFactory.loading(true)
            commonFactory.ajax(commonFactory.pointurl + "/api/user/AddToAssign", { phone: $scope.addBorrMoblie, usertype: $scope.usertype }, function (result) {
                $scope.isadd = true;
                commonFactory.loading(false)
                if (result.code == 1) {
                    toaster.pop('success', '', '添加成功');
                    requestBorrList()
                } else {
                    toaster.pop('warning', '', result.data);
                }
            }, function () {
                commonFactory.loading(false)
                toaster.pop('error', '', '后台错误');
            }, "post");
        }
    }

    var requestBorrList = function () {
        commonFactory.loading(true)
        commonFactory.ajax(commonFactory.pointurl + "/api/user/QueryUsers", $scope.BorrData, function (result) {
            $scope.graybtn = false;
            commonFactory.loading(false)
            if (result.data.count >= 0) {
                $scope.BorrList = result.data.data;
                $scope.BorrListCount = result.data.count;
                $scope.page = Math.ceil(result.data.count / $scope.BorrData.Size);
                for (var i = $scope.BorrList.length - 1; i >= 0; i--) {
                    $scope.BorrList[i].BirthDate = new Date().getFullYear() - new Date($scope.BorrList[i].BirthDate).getFullYear();
                }
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    // 删除
    $scope.delete = function (obj) {
        var modalInstance = $modal.open({
            templateUrl: 'tpl/model/delPmodel.html?v=' + Math.random(),
            controller: ['$scope', '$modalInstance', 'items', 'toaster', 'commonFactory', function ($scope, $modalInstance, items, toaster, commonFactory) {
                $scope.items = items;
                $scope.ok = function () {
                    //删除
                    commonFactory.ajax(commonFactory.pointurl + "/api/User/Delete", { '': $scope.items }, function (result) {
                        if (result.code == 1) {
                            toaster.pop('success', '成功', '删除成功');
                            $modalInstance.close();
                        } else {
                            toaster.pop('error', '失败', result.data);
                            $modalInstance.close();
                        }
                    }, function () {
                        toaster.pop('error', '失败', '后台未返回报错');
                    }, "post");
                }

                $scope.cancel = function () {
                    $modalInstance.close('cancel');
                };
            }],
            size: 'sm',
            backdrop: false,
            resolve: {
                items: function () {
                    return obj;
                }
            }
        });
        modalInstance.result.then(function () {
            requestBorrList();
        }, function () {

        });
    };
    requestBorrList()
}]);
// 预期还款明细
app.controller('fixedpointdetails', ['$scope', '$http', 'commonFactory', 'toaster', '$timeout', function ($scope, $http, commonFactory, toaster, $timeout) {
    var today = new Date()
    $scope.repaymentData = {
        dt: today
    }
    var requesrepayment = function () {
        if (!$scope.repaymentData.dt) {
            toaster.pop('warning', '警告', '请选择日期');
            return;
        }
        $scope.repaymentData.dt = commonFactory.DateFormat($scope.repaymentData.dt, 1);
        commonFactory.loading(true)
        commonFactory.ajax(commonFactory.pointurl + "/api/Repayment/QueryCapitalRepayment", { time: $scope.repaymentData.dt }, function (result) {
            $scope.graybtn = false;
            commonFactory.loading(false)
            if (result.code == 1) {
                $scope.repaymentList = result.data.data.data;
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    requesrepayment()
    $scope.query = function () {
        $scope.graybtn = true;
        requesrepayment()
    }
    // $scope.exportdetail = function () {
    //     if (!$scope.repaymentData.dt) {
    //         toaster.pop('warning', '', '请选择日期');
    //         return;
    //     }
    //     $scope.repaymentData.dt = commonFactory.DateFormat($scope.repaymentData.dt, 1);
    //     $scope.gourl = commonFactory.baseurl + '/api/Product/ExcelRepayProductInfo?Dt=' + $scope.repaymentData.dt
    // }
}]);
// 还款管理
app.controller('fixedpointfinancerepayment', ['$scope', '$http', 'commonFactory', 'toaster', '$timeout', function ($scope, $http, commonFactory, toaster, $timeout) {
    $scope.index = 1;
    $scope.size = 10;
    //下一页
    $scope.next = function () {
        if ($scope.page) {
            if ($scope.index >= $scope.page) {//判断最大页码
                $scope.index = $scope.page;
                return false;
            }
            $scope.index++
            requestProductList();
        }
    }
    //上一页
    $scope.prev = function () {
        if ($scope.index <= 1) {//判断最小页码
            $scope.index = 1;
            return false;
        }
        $scope.index--;
        requestProductList()
    }
    $scope.returndata = {//查询条件
        ProductId: '',//产品id
        AssignUserId: '',// 借款人Id
        AssignInvestUserId: '',// 投资人Id
        FirstOnlineTime: '',// 募集时间/上架时间
        RepayDate: '',// 还款日期
        FullDateStart: '',// 满标开始日期
        FullDateEnd: '',// 满标结束日期
        ProductName: '',//产品名称
        Index: $scope.index,
        Size: $scope.size
    }
    //查询
    $scope.search = function () {
        $scope.graybtn = true;
        $scope.index = 1 //查询后在第一页显示
        if (!$scope.returndata.ProductId) {
            $scope.returndata.ProductId = ''
        }
        if (!$scope.returndata.AssignUserId) {
            $scope.returndata.AssignUserId = ''
        }
        if (!$scope.returndata.AssignInvestUserId) {
            $scope.returndata.AssignInvestUserId = ''
        }
        if (!$scope.returndata.ProductName) {
            $scope.returndata.ProductName = ''
        }
        if ($scope.returndata.FirstOnlineTime) {
            $scope.returndata.FirstOnlineTime = commonFactory.DateFormat($scope.returndata.FirstOnlineTime, 1);
        } else {
            $scope.returndata.FirstOnlineTime = ''
        }
        if ($scope.returndata.FullDateStart) {
            $scope.returndata.FullDateStart = commonFactory.DateFormat($scope.returndata.FullDateStart, 1);
        } else {
            $scope.returndata.FullDateStart = ''
        }
        if ($scope.returndata.FullDateEnd) {
            $scope.returndata.FullDateEnd = commonFactory.DateFormat($scope.returndata.FullDateEnd, 1);
        } else {
            $scope.returndata.FullDateEnd = ''
        }
        if ($scope.returndata.RepayDate) {
            $scope.returndata.RepayDate = commonFactory.DateFormat($scope.returndata.RepayDate, 1);
        } else {
            $scope.returndata.RepayDate = ''
        }
        requestProductList();
    }

    var requestProductList = function () {
        commonFactory.loading(true)
        commonFactory.ajax(commonFactory.pointurl + "/api/repayment/QueryFinanceRepayment", $scope.returndata, function (result) {
            $scope.graybtn = false;
            commonFactory.loading(false)
            if (result.code == 1) {
                $scope.RepaymentTotal = result.data;
                $scope.GetRepaymentList = result.data.productInfos.data;
                $scope.GetRepaymentListTotal = result.data.productInfos.count;
                $scope.page = Math.ceil(result.data.productInfos.count / $scope.size);
            } else {
                toaster.pop('warning', '', '返回其他code')
            }
        }, function () {
            commonFactory.loading(false)
            $scope.graybtn = false;
        }, "post");
    }
    $scope.export = function () {
        if ($scope.returndata.FirstOnlineTime == undefined || $scope.returndata.FirstOnlineTime == '') {
            $scope.returndata.FirstOnlineTime = ''
        } else {
            $scope.returndata.FirstOnlineTime = commonFactory.DateFormat($scope.returndata.FirstOnlineTime, 1);
        }
        if ($scope.returndata.FullDateEnd == undefined || $scope.returndata.FullDateEnd == "") {
            $scope.returndata.FullDateEnd = ''
        } else {
            $scope.returndata.FullDateEnd = commonFactory.DateFormat($scope.returndata.FullDateEnd, 1)
        }
        if ($scope.returndata.FullDateStart == undefined || $scope.returndata.FullDateStart == "") {
            $scope.returndata.FullDateStart = ''
        } else {
            $scope.returndata.FullDateStart = commonFactory.DateFormat($scope.returndata.FullDateStart, 1)
        }
        if ($scope.returndata.RepayDate == undefined || $scope.returndata.RepayDate == "") {
            $scope.returndata.RepayDate = ''
        } else {
            $scope.returndata.RepayDate = commonFactory.DateFormat($scope.returndata.RepayDate, 1)
        }
        if ($scope.returndata.ProductId == undefined || $scope.returndata.ProductId == '') {
            $scope.returndata.ProductId = ''
        }
        if ($scope.returndata.ProductName == undefined || $scope.returndata.ProductName == '') {
            $scope.returndata.ProductName = ''
        }
        if ($scope.returndata.AssignUserId == undefined || $scope.returndata.AssignUserId == '') {
            $scope.returndata.AssignUserId = ''
        }
        if ($scope.returndata.AssignInvestUserId == undefined || $scope.returndata.AssignInvestUserId == '') {
            $scope.returndata.AssignInvestUserId = ''
        }
        // commonFactory.ajax(commonFactory.pointurl + "/api/repayment/DownloadFinanceRepayment", $scope.returndata, function (result) {
        //     console.log(result)
        //     if (result.code == 1) {
        //         console.log(result)
        //     } else {
        //         toaster.pop('warning', '', '返回其他code')
        //     }
        // }, function () {

        // }, "post");
            $scope.gourl = commonFactory.pointurl + '/api/repayment/DownloadFinanceRepayment?firstOnlineTime=' + $scope.returndata.FirstOnlineTime +
                '&fullDateEnd=' + $scope.returndata.FullDateEnd +
                '&fullDateStart=' + $scope.returndata.FullDateStart +
                '&productId=' + $scope.returndata.ProductId +
                '&productName=' + $scope.returndata.ProductName +
                '&repayDate=' + $scope.returndata.RepayDate +
                '&assignUserId=' + $scope.returndata.AssignUserId +
                '&assignInvestUserId=' + $scope.returndata.AssignInvestUserId +
                '&index=' + $scope.index +
                '&size=' + $scope.size
        }
        requestProductList()
    }]);